package com.mdd.common.mapper.order;

import com.mdd.common.core.basics.IBaseMapper;
import com.mdd.common.entity.order.OrderMeal;
import com.mdd.common.vo.MealSaleDataVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * 套餐Mapper
 * @author shenjian
 * @createTime 2023年02月11日 15:06:00
 */
@Mapper
public interface OrderMealMapper extends IBaseMapper<OrderMeal> {

    @Select("<script>" +
            "SELECT od.meal_id as mealId, count(0) as total\n" +
            "FROM ${prefix}order_detail od\n" +
            "LEFT JOIN ${prefix}order o ON o.id = od.order_id AND o.`status` <![CDATA[>]]> 0\n" +
            "WHERE od.meal_id in " +
            "<foreach collection=\"mealIds\" item=\"item\" index=\"index\" open=\"(\" close=\")\" separator=\",\">" +
            "#{item}" +
            "</foreach>" +
            "GROUP BY od.meal_id" +
            "</script>")
    List<MealSaleDataVo> queryMealSaleData(@Param("mealIds") List<Integer> mealIds);
}
